package bomberman.model;

import java.awt.Graphics;

import bomberman.MainGame;
import bomberman.swing.BomJPanel;
import bomberman.util.Constants;
import bomberman.util.GameMap;

/**
 * 道具类（起类名最麻烦了）
 * @author EX-FUHUICHAO001
 *	2016-9-27 16:11:31
 */
public class Property {
	private int x;
	private int y;
	
	// 定义道具样式功能
	private int style = 0;
	
	// 定义道具是否显示
	private boolean isVisible = true;

	public Property(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	public void draw(Graphics g) {
		if(isVisible){
			g.drawImage(GameMap.img_pro_array[style], x, y, MainGame.jPanelIndex);
		}
	}
	
	/**
	 * 随机生成道具，概率为PROPERTY_RANDOM_PERCENT
	 */
	public void randomProperty(){
		if (BomJPanel.random.nextInt(10) < 10 * Constants.PROPERTY_RANDOM_PERCENT) {
			style = BomJPanel.random.nextInt(2);
//			style = BomJPanel.random.nextInt(GameMap.img_pro_array.length);
			// 若当前样式的道具未达到上限，则添加进集合，并设置道具数量自增
			if(Constants.PROPERTY_SIZE[style] < Constants.PROPERTY_MAX_SIZE[style]){
				BomJPanel.properties.add(this);
				Constants.PROPERTY_SIZE[style]++;
			}
		}
	}
	
	/**
	 * 检测坐标位置是否有道具
	 */
	public boolean showProperty(int x, int y){
		if(x == this.x && y == this.y){
			isVisible = true;
			return true;
		}
		return false;
	}
	
	/**
	 * 移除道具
	 */
	public void remove(){
		if(BomJPanel.properties.contains(this)){
			BomJPanel.properties.remove(this);
			isVisible = false;
		}
	}
	
	/**
	 * 改变游戏属性
	 */
	public void changeConstantsValue(){
		switch (style) {
			// 火焰长度自增
			case 0:
				Constants.FLAME_LENGTH++;
				break;
			// 炸弹个数自增
			case 1:
				Constants.BOM_NUMBER++;
				break;
			default:
				break;
		}
	}
	
	
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getStyle() {
		return style;
	}

	public void setStyle(int style) {
		this.style = style;
	}

	public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}
}
